extends Control
signal eye_finish
var twn:Tween
func _ready() -> void:
	pass
@export_range(0.0,0.5,0.01) var width:float = 0.5:
	set(v):
		if twn and twn.is_running():
			return
		else:
			width=clamp(v,0.0,0.5)
			$EyeOpen.material.set_shader_parameter("width",width)
@export_range(0.0,5.0,0.1) var blur:float = 0.0:
	set(v):
		if twn and twn.is_running():
			return
		else:
			blur=clamp(v,0.0,5.0)
			$Blur.material.set_shader_parameter("f",blur)
func eye(open:bool)->void:
	if twn:
		if twn.is_running():await twn.finished
	if open:
		print("open eye")
		$Blur.material.set_shader_parameter("f",5.0)
		$EyeOpen.material.set_shader_parameter("width",0.0)
		twn = create_tween()
		twn.tween_property($EyeOpen.material,"shader_parameter/width",0.2,1.0)
		twn.parallel().tween_property($Blur.material,"shader_parameter/f",2.5,1.0)
		
		twn.tween_property($EyeOpen.material,"shader_parameter/width",0.15,1.0)
		
		twn.tween_property($EyeOpen.material,"shader_parameter/width",0.5,0.7)
		twn.parallel().tween_property($Blur.material,"shader_parameter/f",0.0,0.7)
	else:
		print("close eye")
		$Blur.material.set_shader_parameter("f",0.0)
		$EyeOpen.material.set_shader_parameter("width",0.5)
		twn = create_tween()
		twn.tween_property($EyeOpen.material,"shader_parameter/width",0.2,1.0)
		twn.parallel().tween_property($Blur.material,"shader_parameter/f",2.5,1.0)
		
		twn.tween_property($EyeOpen.material,"shader_parameter/width",0.25,1.0)
		
		twn.tween_property($EyeOpen.material,"shader_parameter/width",0.0,0.7)
		twn.parallel().tween_property($Blur.material,"shader_parameter/f",5.0,0.7)
	await twn.finished
	eye_finish.emit()
